#include <iostream>

using std::cout;
using std::endl;

class Point
{
public:
    Point(int ix = 0, int iy = 0)
    : _ix(ix)
    , _iy(iy)
    {
        cout << "Point(int = 0, int = 0)" << endl;
    }

    //在非静态的成员函数的第一个参数的位置会隐含有一个
    //指针，这个指针会记录对象的地址，这个指针this
    //
    //类型：Point * const this
    void print(/*  this */)
    {
        printf("this = %p\n", this);
        /* this->_ix = 10;//ok */
        /* this = nullptr;//error,不能改变指针的指向 */

        cout << "(" << this->_ix
             << ", " << this->_iy
             << ")" << endl;
    }

    ~Point()
    {
        cout << "~Point()" << endl;
    }

private:
    int _ix;
    int _iy;
};

void test()
{
    Point pt(1, 2);//pt栈对象
    cout << "pt = ";
    pt.print();

    cout << endl;
    Point pt2(10, 50);//pt2也是栈对象
    cout << "pt2 = ";
    pt2.print();

    printf("&pt = %p\n", &pt);
    printf("&pt2 = %p\n", &pt2);
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

